package leetcode.leetcode235;

/**
 * @author czt
 * @version 1.0
 * @since 2025/1/2
 */
public class Leetcode235 {

    public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) {
        TreeNode a = root;
        while(p.val < a.val && q.val < a.val || a.val < p.val && a.val < q.val) {
            if (p.val < a.val) {
                a = a.left;
            } else {
                a = a.right;
            }
        }
        return a;
    }
}
